package org.example;

import java.io.FileWriter;
import java.io.IOException;

public class WriteCtrlChar {
    public static void main(String[] args) throws IOException {

        // 定义一个包含 \u0001 的字符串
        String data = "id\u0001name\u0001age";
        System.out.println(data); // 输出可能像：id^Aname^Aage


        String fileEncoding = System.getProperty("file.encoding");
        System.out.println("你设置的fileEncoding="+fileEncoding);

        String fileName="output_"+fileEncoding+".txt";

        try (FileWriter fw = new FileWriter(fileName)) {
            fw.write("a");
            fw.write('\u0001'); // 写入控制字符
            fw.write("b");
            fw.write("\u0005");// 写入控制字符
            fw.write(System.lineSeparator());
            fw.write("c");
        }
        System.out.println("写入完成.文件是:"+fileName);
    }
}
